<?php

namespace App\Http\Controllers\Site;

use App\B2BProject\Site\HelperControllerBuildTrait;
use App\B2BProject\Site\ArticleCategory;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndustryInfoController extends Controller
{
    use HelperControllerBuildTrait;

    /**
     * 行业资讯
     * @return \Illuminate\View\View
     */
    public function getIndex(){
        return view("host/industryInfo/lister");
    }

    /**
     * 资讯列表
     * @param $info
     * @return $this
     */
    public function getList($info)
    {
        $displayName = ArticleCategory::where('name', $info)->first();
        $list = ArticleCategory::getArticleCollectionByCategoryName($info)->orderBy('created_at',
            'desc')->paginate(20)->chunk(5);
        return view("host/industryInfo/list")->with('list', $list)->with('info', $info)->with('displayName',
            $displayName->display_name);
    }

    /**
     * 详细信息
     * @param $info
     * @param $id
     * @return $this
     */
    public function getDetails($info, $id)
    {
        //根据id查找相关的信息
        $details = ArticleCategory::getArticleCollectionByCategoryName($info)->where('id', $id)->first();
        //查找上一篇
        $prev = ArticleCategory::getArticleCollectionByCategoryName($info)->orderBy('created_at', 'desc')->where('id',
            '<', $id)->first();
        //查找下一篇
        $next = ArticleCategory::getArticleCollectionByCategoryName($info)->orderBy('created_at', 'desc')->where('id',
            '>', $id)->first();
        return view("host/industryInfo/details")->with('details', $details)->with('prev', $prev)->with('next',
            $next)->with('info', $info);
    }

    /**
     * 底部等公共信息
     * @param $info
     * @param $id
     * @return $this
     */
    public function getComm($info, $id)
    {
        //根据id查找相关的信息
        $details = ArticleCategory::getArticleCollectionByCategoryName($info)->where('id', $id)->first();
        //查找上一篇
        $prev = ArticleCategory::getArticleCollectionByCategoryName($info)->orderBy('created_at', 'desc')->where('id',
            '<', $id)->first();
        //查找下一篇
        $next = ArticleCategory::getArticleCollectionByCategoryName($info)->orderBy('created_at', 'desc')->where('id',
            '>', $id)->first();
        return view("host/industryInfo/comm")->with('details', $details)->with('prev', $prev)->with('next',
            $next)->with('info', $info);
    }


}

